package alg20241130;

public class Text {
    public int minSubArrayLen(int target, int[] nums) {
        int n = nums.length;
        int left = 0, right = 0, sum = 0, len = Integer.MAX_VALUE;
        while(right < n){
            //进窗口
            sum += nums[right++];
            //判断
            while(sum > target){
                //出窗口
                sum -= nums[left++];
            }
            //更新结果
            if(sum == target) len = Math.min(len, right - left);

        }
        return len == Integer.MAX_VALUE ? 0 : len;
    }
}
